package com.zdd.ehe;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @title:CodeGenerator
 * @author:ZhuiZhu
 * @description:mybatisplus 自动生成代码
 * @createDate: 2023/3/13  15:09
 */
public class CodeGenerator {

    public static void main(String[] args) {

        String url = "jdbc:mysql://localhost:3306/ehe?serverTimezone=Asia/Shanghai&userUnicode=true&characterEncoding=utf-8";
        String username = "root";
        String password = "root";
        String author = "ZhuiZhu";
        String moduleName = "ehe";
        String mapperLocation = "E:\\ehe\\src\\main\\resources\\mapper";
        String tables = "t_analysis_forecast_data";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            //.fileOverride() // 覆盖已生成文件
                            .outputDir("E:\\ehe\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.zdd") // 设置父包名
                            .moduleName(moduleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, mapperLocation)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables) // 设置需要生成的表名
                            .addTablePrefix("p_", "t_", "w_")// 设置过滤表前缀
                            .addTableSuffix("_data"); // 设置过滤表后缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
